using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using OpenTK.Math;

namespace Dogfight2008.Common.Tests
{
  [TestFixture]
  public class TriangleFixture
  {
    public static Triangle ConstructTriangle()
    {
      return new Triangle(Vector3.UnitX, Vector3.UnitY, Vector3.UnitZ);
    }

    [Test]
    public void Test1() {
      Triangle t = ConstructTriangle();
      Ray r = new Ray(new Vector3(0.1f, 0.1f, 3), new Vector3(0, 0, -1));
      IntersectionResult result = t.Intersect(r);
      Assert.IsTrue(result.DoesIntersect);
    }

    [Test]
    public void Test2() {
      Triangle t = new Triangle(Vector3.Zero, Vector3.UnitX, Vector3.UnitY);
      Ray r = new Ray(new Vector3(0.1f, 0.1f, 3), -Vector3.UnitZ);
      IntersectionResult result = t.Intersect(r);
      Assert.AreEqual(3, result.Param);
    }

    [Test]
    public void Test3()
    {
      Triangle t = new Triangle(Vector3.Zero, Vector3.UnitX, Vector3.UnitY);
      Ray r = new Ray(new Vector3(-1, 0, 3), -Vector3.UnitZ);
      IntersectionResult result = t.Intersect(r);
      Assert.IsFalse(result.DoesIntersect);
    }

    [Test]
    public void AccessPoints()
    {
      Vector3 p1 = new Vector3(0, 1, 2);
      Vector3 p2 = new Vector3(3, 4, 5);
      Vector3 p3 = new Vector3(6, 7, 8);
      Triangle t = new Triangle(p1, p2, p3);
      Assert.IsTrue(Calc.Equal(p1, t.P1));
      Assert.IsTrue(Calc.Equal(p2, t.P2));
      Assert.IsTrue(Calc.Equal(p3, t.P3));
    }

    [Test]
    public void Equals()
    {
      Triangle t1 = ConstructTriangle();
      Triangle t2 = ConstructTriangle();
      Assert.AreEqual(t1, t2);
    }

    [Test]
    public void Equals2()
    {
      Triangle t1 = new Triangle(Vector3.UnitX, Vector3.UnitY, Vector3.UnitZ);
      Triangle t2 = new Triangle(Vector3.UnitX, Vector3.UnitY, new Vector3(4, 5, 6));
      Assert.AreNotEqual(t1, t2);
    }
  }
}
